﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormsCalculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char op = Char.Parse(comboBox1.SelectedItem.ToString());
            double a = Double.Parse(textBox2.Text);
            double b = Double.Parse(textBox1.Text);
            double result;
            switch (op)
            {
                case '+':
                    {
                        result = a + b;
                        textBox3.Text = result.ToString();
                        break;
                    }
                case '-':
                    {
                        result = a - b;
                        textBox3.Text = result.ToString();
                        break;
                    }
                case '*':
                    {
                        result = a * b;
                        textBox3.Text = result.ToString();
                        break;
                    }
                case '/':
                    {
                        if (b == 0)
                        {
                            textBox3.Text = "非法除零操作";
                            break;
                        }
                        result = a / b;
                        textBox3.Text = result.ToString();
                        break;
                    }
                default:
                    {
                        textBox3.Text = "运算符错误";
                        break;
                    }
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
